package com.androidjam.runningacoruna;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;
import com.readystatesoftware.mapviewballoons.BalloonOverlayView;

public class DescriptionItemizedOverlay<Item extends OverlayItem> extends BalloonItemizedOverlay<DescriptionOverlayItem> {

	private ArrayList<DescriptionOverlayItem> m_overlays = new ArrayList<DescriptionOverlayItem>();
	private Context c;
	
	public DescriptionItemizedOverlay(Drawable defaultMarker, MapView mapView) {
		super(boundCenter(defaultMarker), mapView);
		c = mapView.getContext();
	}

	public void addOverlay(DescriptionOverlayItem overlay) {
	    m_overlays.add(overlay);
	    populate();
	}

	@Override
	protected DescriptionOverlayItem createItem(int i) {
		return m_overlays.get(i);
	}

	@Override
	public int size() {
		return m_overlays.size();
	}

	@Override
	protected boolean onBalloonTap(int index, DescriptionOverlayItem item) {
		Toast.makeText(c, "onBalloonTap for overlay index " + index,
				Toast.LENGTH_LONG).show();
		return true;
	}

	@Override
	protected BalloonOverlayView<DescriptionOverlayItem> createBalloonOverlayView() {
		// use our custom balloon view with our custom overlay item type:
		return new DescriptionBalloonOverlayView<DescriptionOverlayItem>(getMapView().getContext(), getBalloonBottomOffset());
	}

}
